

clear all

set more off 


global estimators xtreg

*is it onset (=1) or incidence(=.)?
local cheat 1

if "`cheat'" == "." {
	local on_or_in incidence
}
if "`cheat'" == "1" {
	local on_or_in onset
}

***************************************
***************************************


local title_left Civil War
local title_right Armed Conflict

local left_solid_name Overall Model
local left_dash_name Within Model

local right_solid_name Overall Model
local right_dash_name Within Model

clear all
use model_names
levelsof controls, local(levels) 
clear



foreach on_or_in in onset {






forval p = 1 / 2 {

graph drop _all
local z 1

foreach var in overall within {

if "`var'" == "overall" {
	local varname Overall Model
}
if "`var'" == "within" {
	local varname Within Model
}


if `p' == 1 {
	local what civilwar
}
if `p' == 2 {
	local what armedconflict
}

foreach j in controls {	

	foreach x in $estimators {

		display "`j'"
		display "`k'"
		display "`x'"

		clear

			*graph of war
		use output/for_roc_`on_or_in'`p'

		rename modelname model
		sort model
		merge model using model_names
		sort id fpr tpr
			

		
			
			
			
		local l = 1
		
		*local q 2
		
		local drawem
		local legendem
		foreach k of local levels {
		
			local doit 0
		
			if "`k'" == "fixedeffect"  {
				local nameit Fixed effect
				local doit 1
				local q gs3
				local w dash 
				
			}
			if "`k'" == "chadefaux"  {
				local nameit Keyword count
				local doit 1
				local q gs3
				local w dot
				 
			}
			if "`k'" == "ajps"  {
				local nameit Economic and Political
				local doit 1
				local q gs7
				local w dash 
			}
			if "`k'" == "ward"  {
				local nameit Events
				local doit 1
				local q gs8
				local w solid
			}
			if "`k'" == "pillars"  {
				local nameit Shocks and Institutions
				local doit 1
				local q gs12
				local w solid
			}
			if "`k'" == "rain"  {
				local nameit Rainfall
				local doit 1
				local q gs12
				local w dash
			}
		
			 
			
			if `doit' == 1 {
				*local q = `q' + 2
				local drawem `drawem' (line tpr fpr if what == "`var'" & init == "`j'" & controls == "`k'" & estimation == "`x'", lwidth(medthick) lcolor(`q')  lpattern(`w')  sort)
				local legendem `legendem' `l' "`nameit'"
				local l = `l' + 1
			}
		}
		
		local legendem `legendem' `l' "Topics"
			
			

				twoway  ///
				`drawem' ///			
				(line tpr fpr if what == "`var'" & init == "thetas" & controls == "hachris" & estimation == "`x'", lwidth(medthick) lcolor(black)  lpattern(solid)  sort) ///
				 , ///
				subtitle("`varname'", color(black)) ytitle("") xtitle("") legend( order(`legendem') size(small)) xlabel(,grid) ///
				plotregion(fcolor(white)) graphregion(fcolor(white))  aspectratio(1) ///					
				name(fig`z')
				
				local z = `z' + 1


			


		}
		
		
		
	}

}



grc1leg fig1 fig2, legendfrom(fig1) title("", color(black)  size(small)) subtitle("", color(black) size(small)) plotregion(fcolor(white)) graphregion(fcolor(white)) 

graph export output/figI1.eps ,replace

}

}



